# -*- coding = utf-8 -*-
# @Time : 2023/12/9 20:46
# @Author: tangxl
# @File: connect_redis_cluster.py
# @Software: PyCharm

from rediscluster import RedisCluster

# 测试环境redis集群
r = RedisCluster(
    startup_nodes=[
        {"host": "192.168.17.100", "port": 6381},
        {"host": "192.168.17.100", "port": 6382},
        {"host": "192.168.17.100", "port": 6383}, ])



class RedisClient:
    # redis插入
    def redis_insert(key, value):
        # redis写入
        t = r.set(key, value)
        print("插入{}>>{}",key, t)

    # redis查询
    def redis_query(name):
        res = r.get(name)
        print("查询key:{}>>value:{}",name, res)
        return res

    # redis删除
    def redis_delete(key):
        # redis删除
        t = r.delete(key)
        print("删除key:{}>>{}", key, t)



if __name__ == '__main__':
    value = '"dbc9d88b-cc5b-421c-a369-08eb3939c13f"'
    key = '"0d8b1f62-9445-4cd3-b863-2bcaa05c8bd7"'
    RedisClient.redis_insert(key, value)
    # dd = RedisClient.redis_query("k1")
    # print(dd)
    # RedisClient.redis_delete(key)
    # r.flushdb()
    r.close()